/* This is a generated file. Don't edit. Edit the source instead.
 */

#include <stdlib.h>
#include "cmd_table.h"
#include "ui_cmd.h"

static int ui_cmd_search_all(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 5) return 0;
    char *search_string = argv[0];
    uint64_t size = strtoull(argv[1], NULL, 0);
    int size_restriction = strtoll(argv[2], NULL, 0);
    int file_type = strtoll(argv[3], NULL, 0);
    int id = strtoll(argv[4], NULL, 0);
    if(ui->cb_search_all)
        return ui->cb_search_all(ui, search_string, size, size_restriction, file_type, id);
    return 0;
}

static int ui_cmd_search(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 6) return 0;
    char *hub_address = argv[0];
    char *search_string = argv[1];
    uint64_t size = strtoull(argv[2], NULL, 0);
    int size_restriction = strtoll(argv[3], NULL, 0);
    int file_type = strtoll(argv[4], NULL, 0);
    int id = strtoll(argv[5], NULL, 0);
    if(ui->cb_search)
        return ui->cb_search(ui, hub_address, search_string, size, size_restriction, file_type, id);
    return 0;
}

static int ui_cmd_connect(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 8) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *email = argv[2];
    char *description = argv[3];
    char *speed = argv[4];
    int passive = strtoll(argv[5], NULL, 0);
    char *password = argv[6];
    char *encoding = argv[7];
    if(ui->cb_connect)
        return ui->cb_connect(ui, hub_address, nick, email, description, speed, passive, password, encoding);
    return 0;
}

static int ui_cmd_disconnect(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *hub_address = argv[0];
    if(ui->cb_disconnect)
        return ui->cb_disconnect(ui, hub_address);
    return 0;
}

static int ui_cmd_public_message(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *message = argv[1];
    if(ui->cb_public_message)
        return ui->cb_public_message(ui, hub_address, message);
    return 0;
}

static int ui_cmd_private_message(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 3) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *message = argv[2];
    if(ui->cb_private_message)
        return ui->cb_private_message(ui, hub_address, nick, message);
    return 0;
}

static int ui_cmd_download_file(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 6) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *source_filename = argv[2];
    uint64_t size = strtoull(argv[3], NULL, 0);
    char *target_filename = argv[4];
    char *tth = argv[5];
    if(ui->cb_download_file)
        return ui->cb_download_file(ui, hub_address, nick, source_filename, size, target_filename, tth);
    return 0;
}

static int ui_cmd_download_filelist(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 4) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    int force_update = strtoll(argv[2], NULL, 0);
    int auto_match = strtoll(argv[3], NULL, 0);
    if(ui->cb_download_filelist)
        return ui->cb_download_filelist(ui, hub_address, nick, force_update, auto_match);
    return 0;
}

static int ui_cmd_download_directory(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 4) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *source_directory = argv[2];
    char *target_directory = argv[3];
    if(ui->cb_download_directory)
        return ui->cb_download_directory(ui, hub_address, nick, source_directory, target_directory);
    return 0;
}

static int ui_cmd_queue_remove_target(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *target_filename = argv[0];
    if(ui->cb_queue_remove_target)
        return ui->cb_queue_remove_target(ui, target_filename);
    return 0;
}

static int ui_cmd_queue_remove_source(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 2) return 0;
    char *target_filename = argv[0];
    char *nick = argv[1];
    if(ui->cb_queue_remove_source)
        return ui->cb_queue_remove_source(ui, target_filename, nick);
    return 0;
}

static int ui_cmd_queue_remove_directory(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *target_directory = argv[0];
    if(ui->cb_queue_remove_directory)
        return ui->cb_queue_remove_directory(ui, target_directory);
    return 0;
}

static int ui_cmd_queue_remove_nick(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *nick = argv[0];
    if(ui->cb_queue_remove_nick)
        return ui->cb_queue_remove_nick(ui, nick);
    return 0;
}

static int ui_cmd_queue_remove_filelist(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *nick = argv[0];
    if(ui->cb_queue_remove_filelist)
        return ui->cb_queue_remove_filelist(ui, nick);
    return 0;
}

static int ui_cmd_cancel_transfer(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *target_filename = argv[0];
    if(ui->cb_cancel_transfer)
        return ui->cb_cancel_transfer(ui, target_filename);
    return 0;
}

static int ui_cmd_transfer_stats_interval(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    unsigned int seconds = strtoull(argv[0], NULL, 0);
    if(ui->cb_transfer_stats_interval)
        return ui->cb_transfer_stats_interval(ui, seconds);
    return 0;
}

static int ui_cmd_set_port(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    int port = strtoll(argv[0], NULL, 0);
    if(ui->cb_set_port)
        return ui->cb_set_port(ui, port);
    return 0;
}

static int ui_cmd_set_ip_address(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *ip_address = argv[0];
    if(ui->cb_set_ip_address)
        return ui->cb_set_ip_address(ui, ip_address);
    return 0;
}

static int ui_cmd_add_shared_path(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *path = argv[0];
    if(ui->cb_add_shared_path)
        return ui->cb_add_shared_path(ui, path);
    return 0;
}

static int ui_cmd_remove_shared_path(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *path = argv[0];
    if(ui->cb_remove_shared_path)
        return ui->cb_remove_shared_path(ui, path);
    return 0;
}

static int ui_cmd_shutdown(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 0) return 0;
    if(ui->cb_shutdown)
        return ui->cb_shutdown(ui);
    return 0;
}

static int ui_cmd_set_password(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *password = argv[1];
    if(ui->cb_set_password)
        return ui->cb_set_password(ui, hub_address, password);
    return 0;
}

static int ui_cmd_update_user_info(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 3) return 0;
    char *speed = argv[0];
    char *description = argv[1];
    char *email = argv[2];
    if(ui->cb_update_user_info)
        return ui->cb_update_user_info(ui, speed, description, email);
    return 0;
}

static int ui_cmd_set_slots(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 2) return 0;
    unsigned int slots = strtoull(argv[0], NULL, 0);
    unsigned int per_hub_flag = strtoull(argv[1], NULL, 0);
    if(ui->cb_set_slots)
        return ui->cb_set_slots(ui, slots, per_hub_flag);
    return 0;
}

static int ui_cmd_set_passive(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    int on = strtoll(argv[0], NULL, 0);
    if(ui->cb_set_passive)
        return ui->cb_set_passive(ui, on);
    return 0;
}

static int ui_cmd_forget_search(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    int search_id = strtoll(argv[0], NULL, 0);
    if(ui->cb_forget_search)
        return ui->cb_forget_search(ui, search_id);
    return 0;
}

static int ui_cmd_log_level(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *level = argv[0];
    if(ui->cb_log_level)
        return ui->cb_log_level(ui, level);
    return 0;
}

static int ui_cmd_raw_command(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *command = argv[1];
    if(ui->cb_raw_command)
        return ui->cb_raw_command(ui, hub_address, command);
    return 0;
}

static int ui_cmd_set_priority(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 2) return 0;
    char *target_filename = argv[0];
    unsigned int priority = strtoull(argv[1], NULL, 0);
    if(ui->cb_set_priority)
        return ui->cb_set_priority(ui, target_filename, priority);
    return 0;
}

static int ui_cmd_rescan_share_interval(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    unsigned int seconds = strtoull(argv[0], NULL, 0);
    if(ui->cb_rescan_share_interval)
        return ui->cb_rescan_share_interval(ui, seconds);
    return 0;
}

static int ui_cmd_set_follow_redirects(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    unsigned int flag = strtoull(argv[0], NULL, 0);
    if(ui->cb_set_follow_redirects)
        return ui->cb_set_follow_redirects(ui, flag);
    return 0;
}

static int ui_cmd_grant_slot(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *nick = argv[0];
    if(ui->cb_grant_slot)
        return ui->cb_grant_slot(ui, nick);
    return 0;
}

static int ui_cmd_pause_hashing(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 0) return 0;
    if(ui->cb_pause_hashing)
        return ui->cb_pause_hashing(ui);
    return 0;
}

static int ui_cmd_resume_hashing(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 0) return 0;
    if(ui->cb_resume_hashing)
        return ui->cb_resume_hashing(ui);
    return 0;
}

static int ui_cmd_set_auto_search(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    int enabled = strtoll(argv[0], NULL, 0);
    if(ui->cb_set_auto_search)
        return ui->cb_set_auto_search(ui, enabled);
    return 0;
}

static int ui_cmd_set_hash_prio(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    unsigned int prio = strtoull(argv[0], NULL, 0);
    if(ui->cb_set_hash_prio)
        return ui->cb_set_hash_prio(ui, prio);
    return 0;
}

static int ui_cmd_set_download_directory(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *download_directory = argv[0];
    if(ui->cb_set_download_directory)
        return ui->cb_set_download_directory(ui, download_directory);
    return 0;
}

static int ui_cmd_set_incomplete_directory(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    char *incomplete_directory = argv[0];
    if(ui->cb_set_incomplete_directory)
        return ui->cb_set_incomplete_directory(ui, incomplete_directory);
    return 0;
}

static int ui_cmd_expect_shared_paths(void *user_data, int argc, char **argv)
{
    ui_t *ui = user_data;
    if(ui == NULL) return 0;
    if(argc != 1) return 0;
    int num_shared_paths = strtoll(argv[0], NULL, 0);
    if(ui->cb_expect_shared_paths)
        return ui->cb_expect_shared_paths(ui, num_shared_paths);
    return 0;
}
static cmd_t ui_cmds[] = {
    {"set-passive", ui_cmd_set_passive, 1},
    {"download-file", ui_cmd_download_file, 6},
    {"set-port", ui_cmd_set_port, 1},
    {"queue-remove-nick", ui_cmd_queue_remove_nick, 1},
    {"download-directory", ui_cmd_download_directory, 4},
    {"search-all", ui_cmd_search_all, 5},
    {"download-filelist", ui_cmd_download_filelist, 4},
    {"set-download-directory", ui_cmd_set_download_directory, 1},
    {"set-incomplete-directory", ui_cmd_set_incomplete_directory, 1},
    {"rescan-share-interval", ui_cmd_rescan_share_interval, 1},
    {"update-user-info", ui_cmd_update_user_info, 3},
    {"remove-shared-path", ui_cmd_remove_shared_path, 1},
    {"queue-remove-target", ui_cmd_queue_remove_target, 1},
    {"pause-hashing", ui_cmd_pause_hashing, 0},
    {"set-password", ui_cmd_set_password, 2},
    {"resume-hashing", ui_cmd_resume_hashing, 0},
    {"forget-search", ui_cmd_forget_search, 1},
    {"cancel-transfer", ui_cmd_cancel_transfer, 1},
    {"grant-slot", ui_cmd_grant_slot, 1},
    {"transfer-stats-interval", ui_cmd_transfer_stats_interval, 1},
    {"queue-remove-filelist", ui_cmd_queue_remove_filelist, 1},
    {"set-hash-prio", ui_cmd_set_hash_prio, 1},
    {"set-slots", ui_cmd_set_slots, 2},
    {"set-priority", ui_cmd_set_priority, 2},
    {"queue-remove-source", ui_cmd_queue_remove_source, 2},
    {"public-message", ui_cmd_public_message, 2},
    {"raw-command", ui_cmd_raw_command, 2},
    {"connect", ui_cmd_connect, 8},
    {"set-follow-redirects", ui_cmd_set_follow_redirects, 1},
    {"queue-remove-directory", ui_cmd_queue_remove_directory, 1},
    {"disconnect", ui_cmd_disconnect, 1},
    {"set-auto-search", ui_cmd_set_auto_search, 1},
    {"set-ip-address", ui_cmd_set_ip_address, 1},
    {"expect-shared-paths", ui_cmd_expect_shared_paths, 1},
    {"search", ui_cmd_search, 6},
    {"shutdown", ui_cmd_shutdown, 0},
    {"private-message", ui_cmd_private_message, 3},
    {"add-shared-path", ui_cmd_add_shared_path, 1},
    {"log-level", ui_cmd_log_level, 1},
    {0, 0, -1}
};

ui_t *ui_init(void)
{
    ui_t *ui = calloc(1, sizeof(ui_t));
    return ui;
}

int ui_dispatch_command(const char *line, const char *delimiters,
        int allow_null_elements, ui_t *ui)
{
    return cmd_dispatch(line, delimiters, allow_null_elements,
        ui_cmds, ui);
}
